
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of tblApps
 *
 * @author chema_000
 */
<?php

class Models_tblApp extends Libs_Model {

    protected $queryUnit;

    public function __construct() {
        parent::__construct();
        $this->queryUnit = new Libs_QueryUnit();
    }

    private $id;
    private $title;
    private $images;
    private $category_id;
    private $description;
    private $point;
    private $status;
    private $updatetime;
    private $version;
    private $requirement;
    private $size;
    private $link;
    private $rate;

    public function getId() {
        return $this->id;
    }

    public function getTitle() {
        return $this->title;
    }

    public function getImages() {
        return $this->images;
    }

    public function getCategory_id() {
        return $this->category_id;
    }

    public function getDescription() {
        return $this->description;
    }

    public function getPoint() {
        return $this->point;
    }

    public function getStatus() {
        return $this->status;
    }

    public function getUpdatetime() {
        return $this->updatetime;
    }

    public function getVersion() {
        return $this->version;
    }

    public function getRequirement() {
        return $this->requirement;
    }

    public function getSize() {
        return $this->size;
    }

    public function getLink() {
        return $this->link;
    }

    public function getRate() {
        return $this->rate;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function setTitle($title) {
        $this->title = $title;
    }

    public function setImages($images) {
        $this->images = $images;
    }

    public function setCategory_id($category_id) {
        $this->category_id = $category_id;
    }

    public function setDescription($description) {
        $this->description = $description;
    }

    public function setPoint($point) {
        $this->point = $point;
    }

    public function setStatus($status) {
        $this->status = $status;
    }

    public function setUpdatetime($updatetime) {
        $this->updatetime = $updatetime;
    }

    public function setVersion($version) {
        $this->version = $version;
    }

    public function setRequirement($requirement) {
        $this->requirement = $requirement;
    }

    public function setSize($size) {
        $this->size = $size;
    }

    public function setLink($link) {
        $this->link = $link;
    }

    public function setRate($rate) {
        $this->rate = $rate;
    }

        /**
     * @param mixed $category_id
     */
    

    protected function setCustomerValue($row, $isKey = TRUE) {
        $pro = new Models_tblApp();
        if ($isKey) {
            $pro->setId($row['id']);
        }
        $pro->setCategory_id($row['category_id']);
        $pro->setDescription($row['description']);
        $pro->setTitle($row['title']);
        $pro->setUpdatetime($row['updatetime']);
        $pro->setPoint($row['point']);
        $pro->setStatus($row['status']);
        $pro->setImages($row['images']);
        $pro->setLink($row['link']);
        $pro->setRequirement($row['requirement']);
        $pro->setSize($row['size']);
        $pro->setVersion($row['version']);
        return $pro;
    }

    protected function getColumnAndValue(Models_tblApp $pro, $isKey = FALSE) {
        $arr_data = array();
        if ($isKey) {
            $arr_data['id'] = $pro->getId();
        }
        $arr_data['title'] = $pro->getTitle();
        $arr_data['images'] = $pro->getImages();
        $arr_data['updatetime'] = $pro->getUpdatetime();
        $arr_data['point'] = $pro->getPoint();
        $arr_data['status'] = $pro->getStatus();
        $arr_data['description'] = $pro->getDescription();
        $arr_data['category_id'] = $pro->getCategory_id();
        $arr_data['link'] = $pro->getLink();
        $arr_data['requirement'] = $pro->getRequirement();
        $arr_data['size'] = $pro->getSize();
        $arr_data['version'] = $pro->getVersion();
        return $arr_data;
    }

    public function getAllApp() {
        $listPro = array();
        $execute = $this->queryUnit->getSelect('tbl_apps', NULL, 'updatetime DESC');
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listPro[] = $this->setCustomerValue($row);
            }
        }
        return $listPro;
    }

    public function getProByID($id_pro) {
        $pro = null;
        $execute = $this->queryUnit->getSelect('tbl_apps', "id='$id_pro'");
        if (mysql_num_rows($execute) > 0) {
            $row = mysql_fetch_assoc($execute);
            $pro = $this->setCustomerValue($row);
        }
        return $pro;
    }

    public function getProByCatID($category_id) {
        $listPro = array();
        $execute = $this->queryUnit->getSelect('tbl_apps', " category_id='$category_id'");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listPro[] = $this->setCustomerValue($row);
            }
        }
        return $listPro;
    }

    public function getProOrderByPrice($order) {
        $listPro = array();
        $execute = $this->queryUnit->getSelect('tbl_apps', null, " point $order");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listPro[] = $this->setCustomerValue($row);
            }
        }
        return $listPro;
    }

    public function getSearch($ProName) {
        $listPro = array();

        $execute = $this->queryUnit->getSelect('tbl_apps', "title Like '%" . $ProName . "%'");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listPro[] = $this->setCustomerValue($row);
            }
        }
        return $listPro;
    }

    public function getProByPrice($point, $condition) {
        $listPro = array();

        $execute = $this->queryUnit->getSelect('tbl_apps', " point $condition $point or point= $point");
        if (mysql_num_rows($execute) > 0) {
            while ($row = mysql_fetch_assoc($execute)) {
                $listPro[] = $this->setCustomerValue($row);
            }
        }
        return $listPro;
    }

}
